//
//  LeftViewController.m
//  OpenGLES_Learning
//
//  Created by Mac Center on 7/26/13.
//  Copyright (c) 2013 Mac Center. All rights reserved.
//

#import "LeftViewController.h"
#import "AppViewController.h"

@interface LeftViewController ()
{
    NSMutableArray      *data;
}
@end

@implementation LeftViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    data  = [NSMutableArray new];
    
    NSMutableDictionary *dict = [NSMutableDictionary new];
    [dict setValue:@"chapter 2" forKey:@"title"];
    [dict setValue:@"Chapter2ViewController" forKey:@"class"];
    [data addObject:dict];

    dict = [NSMutableDictionary new];
    [dict setValue:@"chapter 3" forKey:@"title"];
    [dict setValue:@"Chapter3ViewController" forKey:@"class"];
    [data addObject:dict];

    dict = [NSMutableDictionary new];
    [dict setValue:@"chapter 4" forKey:@"title"];
    [dict setValue:@"Chapter4ViewController" forKey:@"class"];
    [data addObject:dict];
    
    dict = [NSMutableDictionary new];
    [dict setValue:@"Draw Earth" forKey:@"title"];
    [dict setValue:@"DrawEarthViewController" forKey:@"class"];
    [data addObject:dict];

    dict = [NSMutableDictionary new];
    [dict setValue:@"Transformation" forKey:@"title"];
    [dict setValue:@"TransformationViewController" forKey:@"class"];
    [data addObject:dict];

    [self.tableview reloadData];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableview Datasoure and Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellIdentitfy = @"CellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentitfy];
    if (cell == nil) {
        cell  = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentitfy];
    }
    NSMutableDictionary *dict = [data objectAtIndex:indexPath.row];
    cell.textLabel.text = [dict objectForKey:@"title"];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSMutableDictionary *dict = [data objectAtIndex:indexPath.row];
    NSString *className = [dict objectForKey:@"class"];
//    [[LeftViewController alloc] initWithNibName:<#(NSString *)#> bundle:<#(NSBundle *)#>]
    GLKViewController *vc = [[NSClassFromString(className) alloc] initWithNibName:className bundle:nil];
    [[AppViewController shared].navigationController popToRootViewControllerAnimated:NO];
    [[AppViewController shared].navigationController pushViewController:vc animated:YES];
    [[AppViewController shared].deckView toggleLeftViewAnimated:YES];
//    [self.navigationController pushViewController:vc animated:YES];
}
@end
